<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:fn="http://java.sun.com/jsp/jstl/functions"
	xmlns:p="http://primefaces.org/ui"
	xmlns:cc="http://java.sun.com/jsf/composite"	>

<cc:interface>
	<cc:attribute name="roles" 					type="java.util.List" 		required="true" />
	<cc:attribute name="header"					type="java.lang.String"		required="true"/>
	
</cc:interface>

<cc:implementation>

	<span id="#{cc.clientId}" >
		<h:form prependId="false">
			<p:outputPanel layout="block" style="min-width:300px;max-width:600px">
				<p:dataTable id="rolesTable" value="#{cc.attrs.roles}" var="role" paginator="true"  
					paginatorAlwaysVisible="false"  paginatorPosition="bottom" rows="8" emptyMessage="#{msgs.NoResults}">
					<p:columnGroup type="header" >  
						<p:row>
							<p:column colspan="8" style="text-align:center;">
								<f:facet name="header">
									<h:outputText value=" #{cc.attrs.header}" />
								</f:facet>
							</p:column>
						</p:row>
						<p:row>
							<p:column colspan="1"  styleClass="ui-table-button-row">
								<f:facet name="header" >
									<p:commandButton  action="#{roleComp.loadAvailableRoles}" oncomplete="waddRoles.show();"  update="@(#{roleComp.jqueryComponentId}\\:addRoles)"
										title="#{msgs.Add}" icon="ui-icon-plus" styleClass="ui-table-button" />
								</f:facet>
							</p:column>		
							<p:column	colspan="2">
								<f:facet name="header">
									<h:outputText value="#{msgs.Name}"/>
								</f:facet>
							</p:column>
							<p:column	colspan="1" >
								<f:facet name="header">
									<h:outputText value="#{msgs.Description}"/>
								</f:facet>
							</p:column> 
						</p:row>	
					</p:columnGroup>
					<p:column colspan="2" headerText="#{msgs.Name}" style="max-height:15px !important;padding-top:0px !important;padding-bottom:0px !important"  >
						<h:outputText value="#{role.name}" />
					</p:column>
					<p:column colspan="1" styleClass="ui-table-button-row">
						<p:commandButton title="#{msgs.Delete}"	action="#{roleComp.deleteRole}"	update="rolesTable" icon="ui-icon-trash" style="height:30px !important" styleClass="ui-table-button"	> 
							<f:setPropertyActionListener target="#{roleComp.role}" value="#{role}"/>
						</p:commandButton>
					</p:column>		
	
					<p:column colspan="1" headerText="#{msgs.Description}">
						<h:outputText value="#{msgs[role.name]}"/>
					</p:column>		
				</p:dataTable>						
			</p:outputPanel>
		</h:form>

		<p:dialog id="addRoles" header="#{msgs.Access}" widgetVar="waddRoles" appendTo="@(body)" modal="true" style="padding: 0px; margin: 0px;"> 
			<h:form id="addRolesForm" prependId="false">
				<h:panelGrid columns="2" cellpadding="2">
					<h:outputLabel 	value="#{msgs.AccessRoles} :" 	/>
		            <p:selectOneMenu id="roleType" value="#{roleComp.selRole}" var="r" converter="#{roleConverter}" height="300" style="width:300px" >
		            	<f:selectItems value="#{roleComp.fullRoles}" var="role" itemLabel="#{role.name}" itemValue="#{role}" />		
						<p:column>  
			                #{r.name} 
			            </p:column>  
				        <p:column>  
                			<p:inputTextarea rows="4" cols="25"	maxlength="60" placeholder="#{msgs.DescriptionOfRole}"
								value="#{msgs[r.name]}" disabled="true" />
            			</p:column>  
		            </p:selectOneMenu>
				</h:panelGrid>
				<p:commandButton value="#{ msgs.Add}"	actionListener="#{roleComp.addRole}"	icon=" ui-icon-search" 
					 process="@form" update="addRolesForm, @(#{roleComp.jqueryComponentId}\\:rolesTable)" rendered="#{not empty roleComp.fullRoles}"  />
			</h:form>
		</p:dialog>


	</span>
</cc:implementation>


</html>